package com.liu.student.controller;

import com.liu.student.entity.Course;
import com.liu.student.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程API控制器
 */
@RestController
@RequestMapping("/api/courses")
public class CourseController {
    
    @Autowired
    private CourseService courseService;

    @GetMapping
    public List<Course> list() { 
        return courseService.findAll(); 
    }

    @PostMapping
    public Course create(@RequestParam String name, @RequestParam Integer capacity) {
        Course course = new Course();
        course.setName(name);
        course.setCapacity(capacity);
        course.setStatus("ACTIVE");
        courseService.save(course);
        return course;
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) { 
        courseService.deleteById(id);
        return true;
    }
}